/*
 * test_detect.cpp
 *
 *  Created on: 2016年3月19日
 *      Author: guyadong
 */
#include <iostream>
#include <sstream>
#include <cmath>
#include "cmdline.h"
#include "adaboost_facedetect_old.h"
#include "file_utilits.h"
#include "time_utilits.h"
using namespace cimg_library;
using namespace gdface;

int main(int argc, char * argv[]){
	cmdline::parser parser;
	parser.add<std::string>("jpeg", 'j', "jpeg image file", true);
	parser.add("count", 'c', "test count,invalid only jpeg is file", false, int(1));

	parser.parse_check(argc, argv);
	try{
		const char *input_jpg_file = parser.get<string>("jpeg").data();		
		auto jpeg_is_folder = gdface::is_folder(input_jpg_file);
		CImgWrapper<uint8_t> image_jpg_gray;
		auto jpeg_data=gdface::load_binary_file(input_jpg_file);

		image_jpg_gray.load_mem_jpeg_gray(jpeg_data);
		if(!jpeg_is_folder)
			image_jpg_gray.display();
		CAdaboostFaceDetect cafd("CascadeInfo");
		tls_clock_probe.start();
		std::vector<FACE_LOCATION> face_info(1024);
		int face_num;
		auto test_count = jpeg_is_folder ? 1 : parser.get<int>("count");
		tls_clock_probe.start();
		for (decltype(test_count) i = 0; i < test_count;++i){
			cafd.RunFaceDetector(image_jpg_gray._data,image_jpg_gray._width,image_jpg_gray._height,face_info.data(),&face_num);
		}
		auto time_cost = tls_clock_probe.end() / test_count;
		cafd.display_face_rect(CImgWrapper<uint8_t>().load_mem_jpeg(jpeg_data)
			, std::vector<FACE_LOCATION>(face_info.data(),face_info.data()+face_num), 
			true,"CPU:",test_count," times,average=", time_cost," seconds");

	}catch(std::exception &e){
		cout<<"exception:"<<e.what()<<endl;
	}catch(...){
		cout<<"exception:unknow"<<endl;
	}
}




